#ifndef GAME_STATE_HPP
#define GAME_STATE_HPP

#include "..\Utils\MovableText.h"

class cTetrisPiece;
class cTetrisBoard;
class Ogre::MovableText;

class GameState : public AppState, Ogre::FrameListener
{
public:
		GameState();

	DECLARE_APPSTATE_CLASS(GameState)
	virtual		void CreateScene();
	virtual 	void Enter();
	virtual 	void Exit();
	virtual 	void Update(double fDeltaTime);
	virtual 	bool Pause();
	virtual 	void Resume();
	virtual		void Restart();

	virtual		bool keyPressed(const OIS::KeyEvent &keyEventRef);
	virtual		bool keyReleased(const OIS::KeyEvent &keyEventRef);
	virtual		bool mouseMoved(const OIS::MouseEvent &arg);
	virtual		bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
	virtual		bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
	virtual		void yesNoDialogClosed(const Ogre::DisplayString& question, bool yesHit);

	virtual		bool frameStarted(const Ogre::FrameEvent& evt);
	virtual		bool frameEnded  (const Ogre::FrameEvent& evt);

	void	CreateGrid(const Ogre::Vector3& pos, float step, float length, int nColumns, int nLines);
	void	CreateMaterial(const char* szName,	const char* szResGroup, const Ogre::ColourValue& color);
	void	Create3DLine(const char* szMaterial, const Ogre::Vector3& startPos, const Ogre::Vector3& endPos);
	Ogre::MovableText*	GetMovableText(const char* szId, const char* szText, const Ogre::Vector3& pos, Ogre::MovableText::HorAlign alignX, Ogre::MovableText::VerAlign alignY);

	void	MoveCamera();
	void	BuildGUI();
	void	ClearPiece(cTetrisPiece& piece);

	void	Score(int lines);	

private:
	OgreBites::ParamsPanel*		m_pDetailsPanel;
	cTetrisPiece*				m_pCurrentPiece;
	cTetrisPiece*				m_pNextPiece;
	cTetrisBoard*				m_pTetrisBoard;
	Ogre::MovableText*			m_pMsgOnScreen;

	Ogre::Vector3				m_TranslateVector;
	Ogre::Vector3				m_CameraPos;
	Ogre::Vector3				m_CameraDir;
	Ogre::Vector3				m_vPieceDir;
	Ogre::Vector3				m_vAdjustDir;

	Ogre::Real					m_MoveSpeed;
	Ogre::Degree				m_RotateSpeed;
	Ogre::Degree				m_RotScale;

	float						m_MoveScale;
	float						m_fPieceSpeedX;
	float						m_fPieceSpeedY;

	int							m_nLevel;
	int							m_nScore;
	int							m_nLines;
	DWORD						m_dwKeyRelease;

	bool						m_bLMouseDown; 
	bool						m_bRMouseDown;
	bool						m_bSettingsMode;
	bool						m_bQuit;	
	bool						m_bSpawnPiece;
	bool						m_bCanBreak;
	bool						m_bGameOver;
};

#endif

